import Vue from 'vue'
import Router from 'vue-router'
// import dangerMsg fm '@/views/safe/dangerMsg/index'
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'
import { transform } from '@/utils/trans'
// import position from' @/views/safe/position'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [{
  path: '/login',
  component: () =>
            import('@/views/login/index'),
  hidden: true
},
{
  path: '/404',
  component: () =>
            import('@/views/404'),
  hidden: true
},

{
  path: '/',
  component: Layout,
  redirect: '/dashboard',
  name: '首页',
  hidden: true,
  alwaysShow: false,
  children: [{
    path: 'dashboard',
    component: () =>
                import('@/views/dashboard/index')
  }]
},
{ path: '*', redirect: '/404', hidden: true }
]
var asyncRouterMap = [
  {
    id: 1,
    path: '/resource',
    alwaysShow: true,
    redirect: 'noredirect',
    component: Layout,
    name: '用户管理',
    meta: { title: '用户管理', icon: 'resource' }
  },
  {
    parentId: 1,
    id: 11,
    path: 'department',
    name: '组织结构',
    component: () =>
                      import('@/views/resource/department/index'),
    meta: { title: '组织结构' }
  },
  {
    parentId: 1,
    id: 12,
    path: 'user',
    name: '用户信息',
    component: () =>
                      import('@/views/basicInformation/userList'),
    meta: { title: '用户信息' }
  },
  {
    parentId: 1,
    id: 13,
    path: 'roleList',
    name: '角色列表',
    component: () =>
                      import('@/views/basicInformation/roleList'),
    meta: { title: '角色列表' }
  },
  {
    parentId: 1,
    id: 14,
    path: 'organizationList',
    name: '组织机构',
    component: () =>
                      import('@/views/basicInformation/organizationList'),
    meta: { title: '组织机构' }
  },
  {
    id: 2,
    path: '/party',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: '权限管理',
    meta: { title: '权限管理', icon: 'partyIcon' }
  },
  {
    parentId: 2,
    id: 21,
    path: 'party',
    name: '用户角色',
    component: () =>
                      import('@/views/party/party/index'),
    meta: { title: '用户角色' }
  },
  {
    parentId: 2,
    id: 22,
    path: 'partyUser',
    name: '移动端功能权限',
    component: () =>
                      import('@/views/party/partyUser/index'),
    meta: { title: '移动端功能权限' }
  },
  {
    parentId: 2,
    id: 23,
    path: 'partyUser',
    name: '角色权限',
    component: () =>
                      import('@/views/party/partyUser/index'),
    meta: { title: '角色权限' }
  },
  {
    id: 3,
    path: '/partyBranch',
    alwaysShow: true,
    redirect: 'noredirect',
    component: Layout,
    name: '安全隐患',
    meta: { title: '安全隐患', icon: 'partyBranch' }
  },
  {
    parentId: 3,
    id: 31,
    path: 'dangerMsg',
    name: '隐患信息',
    component: () =>
                      import('@/views/safe/dangerMsg/index'),
    meta: { title: '隐患信息' }
  },
  {
    parentId: 3,
    id: 32,
    path: 'trajectory',
    name: '行走轨迹',
    component: () =>
                      import('@/views/safe/trajectory'),
    meta: { title: '行走轨迹' }
  },
  {
    parentId: 3,
    id: 33,
    path: 'position',
    name: '定位任务11',
    component: () =>
                      import('@/views/safe/position'),
    meta: { title: '定位任务11' }
  },
  {
    parentId: 3,
    id: 34,
    path: 'selfReported',
    name: '人员分布',
    component: () =>
                      import('@/views/safe/personnelDistribution/index'),
    meta: { title: '人员分布' }
  }
]
export let routers = []
routers = transform(asyncRouterMap, 'id', 'parentId', 'children')
export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap.concat(routers)
})
